OperationTree = function(){
	OperationTree.superclass.constructor.call(this, {
		region : "west",
		title : "网站维护",
		split : true,
		width : 225,
		minSize : 175,
		maxSize : 400,
		collapsible : true,
		margins : "0 0 5 5",
		cmargins : "0 5 5 5",
		rootVisible : false,
		lines : false,
		autoScroll : true,
		root : new Ext.tree.TreeNode("网站维护")
    });
	
	this.on('added', this.onAdded, this);
}

Ext.extend(OperationTree, Ext.tree.TreePanel, {
	onAdded : function(){
		var obj = this;
		var query = [];
		for (var i = 0; i < Authority.length; i ++)
			for (var j = 0; j < Authority[i].items.length; j ++)
				query.push(Authority[i].items[j].authority);
		Ext.Ajax.request({
			url: "/manage/haveAuthority",
			params : {auth : Ext.util.JSON.encode(query)},
			method : "GET",
			success: function(response, options){
				var data = Ext.util.JSON.decode(response.responseText);
				if (data == "error"){
					Ext.Msg.alert("错误", "参数错误...");
				}  else if (data == "not logged in"){
					Ext.Msg.alert("错误", "请登录...");
				}  else {
					var loc = 0;
					for (var i = 0; i < Authority.length; i ++){
						var node = null;
						for (var j = 0; j < Authority[i].items.length; j ++, loc ++){
							if (data[loc] == "y"){
								if (node == null){
									node = new Ext.tree.TreeNode(Authority[i].name);
									obj.root.appendChild(node);
								}
								n = new Ext.tree.TreeNode(Authority[i].items[j].name);
								node.appendChild(n);
								n.objName = Authority[i].items[j].objName;
								n.on({
									"click" : function(){
										obj.fireEvent("nodeclick", this.objName);
									}
								});
							}
						}
					}
				}  
			},
			failure : function(){
				Ext.Msg.alert("错误", "获取信息错误...");
			}
		});
	}
});

Ext.reg("App.OperationTree", OperationTree); 